// var $parentNode = window.parent.document;

// function $childNode(name) {
//     return window.frames[name]
// }

// // tooltips
// $('.tooltip-demo').tooltip({
//     selector: "[data-toggle=tooltip]",
//     container: "body"
// });

// // 使用animation.css修改Bootstrap Modal
// $('.modal').appendTo("body");

// $("[data-toggle=popover]").popover();


//判断当前页面是否在iframe中
if (top == this) {
    var gohome = '<div class="gohome"><a class="animated bounceInUp" href="index.html?v=4.0" title="返回首页"><i class="fa fa-home"></i></a></div>';
    $('body').append(gohome);
}

//animation.css
function animationHover(element, animation) {
    element = $(element);
    element.hover(
        function () {
            element.addClass('animated ' + animation);
        },
        function () {
            //动画完成之前移除class
            window.setTimeout(function () {
                element.removeClass('animated ' + animation);
            }, 2000);
        });
}

//拖动面板
function WinMove() {
    var element = "[class*=col]";
    var handle = ".ibox-title";
    var connect = "[class*=col]";
    $(element).sortable({
            handle: handle,
            connectWith: connect,
            tolerance: 'pointer',
            forcePlaceholderSize: true,
            opacity: 0.8,
        })
        .disableSelection();
};

//保存内容
function saveDataContents() {
    if ($('#tab-1')){
        var roadName = $("#roadName").val();
        var roadPlace = $("#roadPlace").val();
        var roadLength = $('#roadLength').val();
        var roadWidth = $('#roadWidth').val();
        var liqingArea = $("#liqingArea").val();
        var footpathArea = $('#footpathArea').val();
        var roadSpecialCase = $('#roadSpecialCase').val();
        var roadRemark = $('#roadRemark').val();

        if(isNull(roadName)){
            alert("请输入道路名称!");
            return;
        }

        if(!validLength(roadName,200)){
            alert("道路名称过长，请重新输入!");
            return;
        }

        if(isNull(roadPlace)){
            alert("请输入起止地点!");
            return;
        }

        if(isNull(roadLength)){
            alert("请输入道路长度!");
            return;
        }

        if(!validNumber(roadLength)){
            alert("请在道路长度输入框中填数字！");
            return;
        }

        if(isNull(roadWidth)){
            alert("请输入道路宽度!");
            return;
        }

        if(!validNumber(roadWidth)){
            alert("请在道路宽度输入框中填数字！");
            return;
        }

        if(isNull(liqingArea)){
            alert("请输入沥青面积!");
            return;
        }

        if(!validNumber(liqingArea)){
            alert("请在沥青面积输入框中填数字！");
            return;
        }

        if(isNull(footpathArea)){
            alert("请输入步道面积!");
            return;
        }

        if(!validNumber(footpathArea)){
            alert("请在步道面积输入框中填数字！");
            return;
        }

        // if(!validCN_ENString1_100(roadRemark)){
        //     alert("备注字数过多!请输入100字以内");
        //     return;
        // }

        var url = '/admin/dataRecord/addNewRoadData';
        var data = {
            'roadName' : roadName,
            'roadPlace' : roadPlace,
            'roadLength' : roadLength,
            'roadWidth' : roadWidth,
            'liqingArea' : liqingArea,
            'footpathArea' : footpathArea,
            'roadSpecialCase' : roadSpecialCase,
            'roadRemark' : roadRemark
        };
        console.log(data);
        $.ajax({
            url: url,
            dataType: 'json',
            type: 'POST',
            contentType:"application/json",
            data: JSON.stringify(data),
            success:function (data) {
                $("#tab-1").html(data);
                alert("添加成功！");
                window.location.href = "/admin/dataRecord";
            }
        });
    }else if($('#tab-2')){
        var hutongName = $("#hutongName").val();
        var materialName = $("#materialName").val();
        var materialSpecification = $('#materialSpecification').val();
        var numbers = $('#numbers').val();
        var pipeRemark = $("#pipeRemark").val();
        var constructionTechnology = $('#constructionTechnology').val();
        var pipeSpecialCase = $('#pipeSpecialCase').val();

        var url = '/admin/dataRecord/addNewPipeData';
        var data = {
            'hutongName' : hutongName,
            'materialName' : materialName,
            'materialSpecification' : materialSpecification,
            'numbers' : numbers,
            'pipeRemark' : pipeRemark,
            'constructionTechnology' : constructionTechnology,
            'pipeSpecialCase' : pipeSpecialCase
        };
        console.log(data);
        $.ajax({
            url: url,
            dataType: 'json',
            type: 'POST',
            contentType:"application/json",
            data: JSON.stringify(data),
            success:function (data) {
                $("#tab-2").html(data);
                alert("添加成功！");
                window.location.href = "/admin/dataRecord"
            }
        });
    }else {
        var slowRoadName = $("#slowRoadName").val();
        var ownership = $("#ownership").val();
        var slowRoadPlace = $('#slowRoadPlace').val();
        var rank = $('#rank').val();
        var slowRoadLength = $("#slowRoadLength").val();
        // var footPathArea = $('#foodpathArea').val();
        // var roadRemark = $('#roadRemark').val();

        var url = '/admin/dataRecord/addNewRoadData';
        var data = {
            'slowRoadName' : slowRoadName,
            'ownership' : ownership,
            'slowRoadPlace' : slowRoadPlace,
            'rank' : rank,
            'slowRoadLength' : slowRoadLength,
            // 'footPathArea' : footPathArea,
            // 'roadRemark' : roadRemark
        };
        console.log(data);
        $.ajax({
            url: url,
            dataType: 'json',
            type: 'POST',
            contentType:"application/json",
            data: JSON.stringify(data),
            success:function (data) {
                alert("添加成功！");
                $("#tab-3").html(data);
            }
        });
    }

}

//取消
function cancels() {
    location.reload();
}

function getFilePath(roadSpecialCase) {
    if(roadSpecialCase){
        if(window.navigator.userAgent.indexOf("MSIE")>=1){
            roadSpecialCase.select();
            return document.getSelection().createRange().text;
        }else if(window.navigator.userAgent.indexOf("Firefox")>=1){
            if(roadSpecialCase.files){
                return roadSpecialCase.files.item(0).getAsDataURL();
            }
            return roadSpecialCase.value;
        }
        return roadSpecialCase.value;
    }
}
